package com.tools;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Arrays工具类
 */
public class ArraysTools {
    public static void main(String[] args) {
        //复制数组
        String[] intro = new String[]{"沉", "默", "王", "二"};
        java.util.Arrays.copyOf(intro, 3);
        //比较
        boolean result = Arrays.equals(new String[]{"沉", "默", "王", "二"}, intro);
        //排序
        Arrays.sort(intro);
        //查找
        int exact = Arrays.binarySearch(intro, "二");
        //转流
        System.out.println(Arrays.stream(intro).count());

        //Arrays.asList() 返回的是 java.util.Arrays.ArrayList
        //并不是 java.util.ArrayList，它的长度是固定的，无法进行元素的删除或者添加。
        List<String> res = Arrays.asList(intro);
        //所以必须这样才可以进行后续的增删
        ArrayList<String> res1 = new ArrayList<>(Arrays.asList(intro));

        /**
         * setAll
         *      i 就相当于是数组的下标，值从 0 开始，到 9 结束，
         *      那么 i * 10 就意味着值从 0 * 10 开始，到 9 * 10 结束，
         *      来看一下输出结果：
         */
        int[] array = new int[10];
        Arrays.setAll(array, i -> i * 10);
        System.out.println(Arrays.toString(array));


        /**
         * parallelPrefix
         *  Arrays.parallelPrefix(array, (left, right) -> {
         *             System.out.println(left + "," + right);
         *             return left + right;
         *         });
         */
        int[] arr = new int[]{1, 2, 3, 4};

        Arrays.parallelPrefix(array, (left, right) -> left + right);
        System.out.println(Arrays.toString(arr));
    }
}
